{% layout = 'dashboard/layout_dashboard.html' %}

<!-- 项目列表 -->
<div class="menublock border-right p-2">
    <div class="container-fluid p-0">
        <i class="fa fa-list mr-2"></i><label class="title">项目列表</label>
        
        <div class="btn-link pull-right" onclick="return create_task();">
            <i class="fa fa-plus mr-1"></i>发布任务
        </div>
    </div>
    
    <hr class="mb-1 mt-0 mx-0">

    <div id="projects">
        {% for idx, info in ipairs(projs) do %}
        <div class="card card-proj mb-1 rounded-0" style="background-color: lightgray">
            <div class="card-header rounded-0 p-2" style="background-color: lightgray">
                <div class="m-0" data-toggle="collapse" data-target='#proj-menu-{{info.id}}' aria-expanded="true" aria-controls="proj-menu-{{info.id}}">
                    <b>{{info.name}}</b>
                    {% if info.repo and #info.repo > 0 then %}
                    <a href="{{info.repo}}"><i class="fa fa-link"></i></a>
                    {% end %}
                    <div class="pull-right">
                        <span class="badge badge-info">{{roles[info.role]}}</span>
                    </div>
                </div>
            </div>

            <div id="proj-menu-{{info.id}}" class="collapse {{ idx == 1 and 'show' or '' }}" data-parent="#projects">
                <div class="card-body list-group list-group-flush m-0 p-0">
                    <a href="#" class="list-group-item list-group-item-action py-1" onclick="return get_proj_info(this, '/dashboard/projects/get_tasks', '{{info.id}}', '{{info.name}}');">任务计划</a>
                    <a href="#" class="list-group-item list-group-item-action py-1" onclick="return get_proj_info(this, '/dashboard/projects/get_reports', '{{info.id}}', '{{info.name}}');">项目周报</a>
                    {% if info.is_admin == 1 then %}
                    <a href="#" class="list-group-item list-group-item-action py-1" onclick="return get_proj_info(this, '/dashboard/projects/get_can_archive', '{{info.id}}', '{{info.name}}');">验收管理</a>
                    <a href="#" class="list-group-item list-group-item-action py-1" onclick="return get_proj_info(this, '/dashboard/projects/get_holidays', '{{info.id}}', '{{info.name}}');">假日管理</a>
                    <a href="#" class="list-group-item list-group-item-action py-1" onclick="return get_proj_info(this, '/dashboard/projects/get_members', '{{info.id}}', '{{info.name}}');">管理成员</a>
                    {% end %}
                </div>
            </div>                
        </div>
        {% end %}
    </div>
</div>

<!-- 内容面板 -->
<div id="project-detail" class="contentblock">
</div>

<script>
var last_filter_menu = $('#projects .card:first .card-body a:first');
function get_proj_info(btn, url, id, name) {
    if (last_filter_menu) $(last_filter_menu).removeClass('list-group-item-secondary');
    last_filter_menu = btn;
    $(last_filter_menu).addClass('list-group-item-secondary');
    
    $('#project-detail').empty();
    $('#project-detail').get(0).innerHTML = '<div class="text-center text-muted" style="margin-top: 40%"><i class="fa fa-spinner fa-spin fa-3x fa-fw"></i></div>';

    $.post(url, { pid: id, pname: name }, function(ret) {
        $('#project-detail').empty();
        $('#project-detail').append($(ret));
    }, 'html');
}

last_filter_menu.click();

function create_task() {
    $.post('/dashboard/tasks/try_create', {}, function(ret) {
        $('#project-detail').empty();
        $('#project-detail').append($(ret));
    }, 'html');
}
</script>